import request from '@/utils/request'
import type {
  SpuTradeMarkResponse,
  SpuResponseData,
  SpuImageWallResponse,
  spuSaleAttrValueResponse,
  SaleAttrSelectDataResponse,
  SpuList,
  AddSku,
  ResponseData,
  skuValueData,
} from './type'

enum API {
  SPULIST_URL = '/admin/product/',
  SUPTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  SPUIMAGEWALL_URL = '/admin/product/spuImageList/',
  SPUATTRLIST_URL = '/admin/product/spuSaleAttrList/',
  BASESALEATTRLIST_URL = '/admin/product/baseSaleAttrList',
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  ADDSKU_URL = '/admin/product/saveSkuInfo',
  FINDSKU_URL = '/admin/product/findBySpuId/',
  DELETESPU_URL = '/admin/product/deleteSpu/',
}
//获取SPU信息
export const getSpuList = (
  page: number,
  limit: number,
  c3Id: number | string,
) =>
  request.get<any, SpuResponseData>(
    API.SPULIST_URL + `${page}/${limit}?category3Id=${c3Id}`,
  )
//获取品牌信息
export const getSpuTradeMark = () =>
  request.get<any, SpuTradeMarkResponse>(API.SUPTRADEMARK_URL)
//获取商品照片墙数据
export const getSpuImageWall = (spuId: number) =>
  request.get<any, SpuImageWallResponse>(API.SPUIMAGEWALL_URL + spuId)
//获取spu销售属性列表
export const getSaleSpuAttr = (spuId: number) =>
  request.get<any, spuSaleAttrValueResponse>(API.SPUATTRLIST_URL + spuId)
//销售属性下拉框
export const getSaleAttrSelect = () =>
  request.get<any, SaleAttrSelectDataResponse>(API.BASESALEATTRLIST_URL)
//添加修改SPU
export const addSpu = (data: SpuList) => {
  if (data.id) {
    //修改SPU
    return request.post<any, any>(API.UPDATESPU_URL, data)
  } else {
    return request.post<any, any>(API.ADDSPU_URL, data)
  }
}
//添加一个SKU
export const addSku = (data: AddSku) =>
  request.post<any, ResponseData>(API.ADDSKU_URL, data)
//查看SKU
export const lookSku = (spuId: number) =>
  request.get<any, skuValueData>(API.FINDSKU_URL + spuId)
export const reqDeleteSpu = (spuId: number) =>
  request.delete<any, any>(API.DELETESPU_URL + spuId)
